/**
 * 
 */
package com.novartis.nims.trialsubmitter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.pixelmed.dicom.AttributeTag;

/**
 * @author snydejo1
 *
 */
class Trial {
	private Document mDocument;
	
	private String mSourceDirectory;
	private String mSubmissionDirectory;
	
	private ApplicationConfiguration mConfiguration;
	
	private String mSubmissionNumber;
	
	Trial(String sourceDir, String submissionDir, String submissionNumber, ApplicationConfiguration config) {
		mSourceDirectory = sourceDir;
		mSubmissionDirectory = submissionDir;
		mConfiguration = config;
		mSubmissionNumber = submissionNumber;
		initialize();
	}
	
	private void initialize() {
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder = null;
		try {
			docBuilder = dbFactory.newDocumentBuilder();
		} catch (ParserConfigurationException e) {
			// TODO throw TrialSubmitterException
			e.printStackTrace();
		}
		mDocument = docBuilder.newDocument();
		
		Element root = mDocument.createElement("submission");
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
		String dateTime = dateFormat.format(new Date());
		root.setAttribute("croid", this.getCROName());
		root.setAttribute("fileidnum", mSubmissionNumber);
		root.setAttribute("asofdatetime", dateTime);
		root.setAttribute("creationdatetime", dateTime);
		mDocument.appendChild(root);
	}

	Document getDocument() {
		return mDocument;
	}

	void setDocument(Document document) {
		mDocument = document;
	}

	String getSourceDirectory() {
		return mSourceDirectory;
	}

	void setSourceDirectory(String sourceDirectory) {
		mSourceDirectory = sourceDirectory;
	}

	String getSubmissionDirectory() {
		return mSubmissionDirectory;
	}

	void setSubmissionDirectory(String submissionDirectory) {
		mSubmissionDirectory = submissionDirectory;
	}

	
	boolean getVisitsOrganized() {
		return mConfiguration.getVisitsOrganized();
	}

	boolean getAbortOnFileMissingVisitKey() {
		return mConfiguration.getAbortOnFileMissingVisitKey();
	}

	boolean getAbortOnFileMissingScanKey() {
		return mConfiguration.getAbortOnFileMissingScanKey();
	}

	boolean getAbortOnFileMissingFileKey() {
		return mConfiguration.getAbortOnFileMissingFileKey();
	}

	boolean getAbortOnFileMissingScanName() {
		return mConfiguration.getAbortOnFileMissingScanName();
	}

	boolean getAbortOnFileWithDuplicateFileKey() {
		return mConfiguration.getAbortOnFileWithDuplicateFileKey();
	}

	boolean getAbortOnUnspecifiedFileError() {
		return mConfiguration.getAbortOnUnspecifiedFileError();
	}
	
	
	int getFileMinimumKB() {
		return mConfiguration.getFileMinimumKB();
	}

	String getCROName() {
		return mConfiguration.getCROName();
	}

	String getUnscheduledVisitIdentifier() {
		return mConfiguration.getUnscheduledVisitIdentifier();
	}

	AttributeTag getVisitKey() {
		return mConfiguration.getVisitKey();
	}

	AttributeTag getScanKey() {
		return mConfiguration.getScanKey();
	}

	AttributeTag getFileKey() {
		return mConfiguration.getFileKey();
	}

	AttributeTag getScanName() {
		return mConfiguration.getScanName();
	}
}
